﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using DAL;
using Entity;
public partial class admin_TypeManagerList : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["LoginUser"] == null)
        {
            //Response.Write(" <script> top.location.href= 'login.aspx'; </script> ");
            return;
        }
        if (!IsPostBack)
        {
            LoadTree();
        }
    }

    /// <summary>
    /// 加载 树
    /// </summary>
    private void LoadTree()
    {

        List<TypeManager> lst = TypeManagerDAL.Instance.SelectUserInfo("");
        TreeNode node = null;
        for (int i = 0; i < lst.Count; i++)
        {
            if (lst[i].Parent_id==0)
            {
                node = new TreeNode(lst[i].Name, lst[i].ID.ToString());
                tvType.Nodes.Add(AddNodes(node, lst));
            }
        }
    }

    /// <summary>
    /// 利用递归加载子菜单
    /// </summary>
    /// <param name="node"></param>
    /// <param name="types"></param>
    /// <returns></returns>
    private TreeNode AddNodes(TreeNode FNode, List<TypeManager> lst)
    {
        TreeNode node = null;
        for (int i = 0; i < lst.Count; i++)
        {
            if (FNode.Value.ToString() == lst[i].Parent_id.ToString())
            {
                node = new TreeNode(lst[i].Name, lst[i].ID.ToString());
                FNode.ChildNodes.Add(AddNodes(node, lst));
            }
        }
        return FNode;
    }
}